package com.ourteam.product.model.api;

import com.ourteam.product.model.domain.ProductModelPropertyRelateBean;
import com.ourteam.product.model.service.IProductModelService;
import com.ourteam.product.model.service.ProductModelServiceFactory;

public class ProductModelPropertyRelateHelper {

	static final IProductModelService PRODUCT_MODEL_SERVICE = ProductModelServiceFactory.getProductModelService();

	private ProductModelPropertyRelateBean modelPropertyRelateBean;

	public ProductModelPropertyRelateHelper(
			ProductModelPropertyRelateBean modelPropertyRelateBean) {
		super();
		this.modelPropertyRelateBean = modelPropertyRelateBean;
	}

	public boolean isKeyRelation() throws Exception {

//		ProductModelPropertyRelateDAOQueryBean queryBean = new ProductModelPropertyRelateDAOQueryBean();
//
//		queryBean
//				.createCriteria()
//				.andPropertyIdEqualTo(modelPropertyRelateBean.getPropertyId())
//				.andRelatedTypeEqualTo(
//						ProductModelRelateTypeEnum.MAP_TABLE.getName());
//
//		return PRODUCT_MODEL_SERVICE
//				.queryProductModelPropertyRelateCount(queryBean) > 0;
		
		return "RELATE_KEY".equals(this.modelPropertyRelateBean.getRelatedConfig());
	}

	public ProductModelPropertyHelper getProperty() throws Exception {
		return ProductModelPropertyHelper
				.getInstance(this.modelPropertyRelateBean.getPropertyId());
	}

	public ProductModelPropertyHelper getRelatedProperty() throws Exception {
		return ProductModelPropertyHelper
				.getInstance(this.modelPropertyRelateBean
						.getRelatedPropertyId());
	}

	public String getRelateType() {
		return this.modelPropertyRelateBean.getRelatedType();
	}
	
	public String getRelateConfig() {
		return this.modelPropertyRelateBean.getRelatedConfig();
	}
}
